﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Base.DAL;
using Base.BLL;
using Base.Util;
using System.ComponentModel;
using MPSystem.Models;
using Ay.Framework.WPF;
using ADX.Views;

namespace MPSystem.Views.YFQ
{
    /// <summary>
    /// DP_test_Condition2.xaml 的交互逻辑  综采监测报表查询条件
    /// </summary>
    public partial class ZCYLPage_testCondition : Page
    {
        public Dictionary<string, string> Cond = new Dictionary<string, string>();
        public static ZCYLPage_testCondition _Me = null;
        public static ZCYLPage_testCondition Me
        {
            get
            {
                if (_Me == null)
                {
                    _Me = new ZCYLPage_testCondition();
                }
                _Me.UpdateCond();
                return _Me;
            }
            set { _Me = value; }
        }
        int gzmbh = 0;

        public ZCYLPage_testCondition()
        {
            InitializeComponent();
            LoadData();
            Me = this;
        }

      
        public void LoadData()
        {
            #region 加载立柱选择
            var cs = ConfigService.FindZc(ZCYLPage_test.cqbh, ZCYLPage_test.gzmbh);
            if (cs == null)
            {
                colLZ.IsEnabled = false;
            }
            else
            {
                colLZ.Items.Add("整架");
                colLZ.Items.Add(cs.FIRSTTD);
                colLZ.Items.Add(cs.SECONDTD);
                colLZ.SelectedIndex = 0;
            }
            #endregion
            LoadBH();
            Begtime.Date = DateTime.Now.Date;
            Endtime.Date = DateTime.Now.Date+new TimeSpan(23,59,59);
        }
        #region 读取压力分站
        public void LoadBH()
        {
            if (gzmbh == ZCYLPage_test.gzmbh && gzmbh > 0) return;
            gzmbh = ZCYLPage_test.gzmbh;
            var li_ylfz = ConfigService.GetZcWz(ZCYLPage_test.gzmbh);
            Items = new Dictionary<string, object>();
            
            if (li_ylfz.Count() > 0)
            {
                foreach (var r in li_ylfz)
                {
                    Items.Add(r.YLFJBH.ToString(), r.YLFJBH.ToString());
                }
            }
            MC.ItemsSource = Items;
            MC.SelectedItems = Items.Clone() as Dictionary<string, object>;
        }
        #endregion

        public void UpdateCond()
        {
            Cond.Clear();
            try
            {
                if (MC.SelectedItems == null)
                {
                    AyMessageBox.ShowError("压力分站必须选择！");
                    return;
                }
                if (colLZ.IsEnabled && colLZ.SelectedValue == null)
                {
                    AyMessageBox.ShowError("立柱必须选择！");
                    return;
                }
                //确认多选下拉数据
                string str_List = "";
                foreach (var item in MC.SelectedItems.Keys)
                {
                    if (str_List == "")
                        str_List = item.ToString();
                    else
                        str_List += "," + item.ToString();
                }
                //确认单位
                string strDW = "";
                if (KN.IsChecked == true)
                    strDW = "KN";
                else
                    strDW = "MPa";
                //确认是否显示曲线
                string draw = IfVisible.IsChecked == true?"1":"0";
                
                Cond.Add("zbhs", str_List);
                Cond.Add("dtStart", Begtime.Text.ToString());
                Cond.Add("dtEnd", Endtime.Text.ToString());
                Cond.Add("channel", colLZ.SelectedIndex.ToString());
                Cond.Add("rzbh", Rzbh.Text);
                Cond.Add("minP", Hgccl.Text.ToString());
                Cond.Add("dw", strDW);
                Cond.Add("draw", draw);
                string sign = "";
                if (C1.IsChecked==true) sign += "总工：       ";
                if (C2.IsChecked == true) sign += "生产科：       ";
                if (C3.IsChecked == true) sign += "区队：       ";
                if (C4.IsChecked == true) sign += "报表人：       ";
                if (C5.IsChecked == true) sign += TYj.Text+"：";
                Cond.Add("sign", sign);
            }
            catch { }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {  
            this.CloseParentWindow();
        }
        #region 多选下拉框使用
        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        private Dictionary<string, object> _items;
        private Dictionary<string, object> _selectedItems;
        public Dictionary<string, object> Items
        {
            get
            {
                return _items;
            }
            set
            {
                _items = value;
                NotifyPropertyChanged("Items");
            }
        }
        public Dictionary<string, object> SelectedItems
        {
            get
            {
                return _selectedItems;
            }
            set
            {
                _selectedItems = value;
                NotifyPropertyChanged("SelectedItems");
            }
        }
        private void Submit()
        {
            foreach (KeyValuePair<string, object> s in SelectedItems)
                MessageBox.Show(s.Key);
        }
        #endregion

       
    }
}
